home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_6.zip / BIND.C < prev    next >
C/C++ Source or Header  |  1993-07-29  |  9KB  |  328 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* Bind.c */
  21.  
  22. #include <externs.h>
  23.  
  24. extern void AVL_MAKE_UNIT_DATE(AVL_EDIT_WINDOW_PTR w);
  25.  
  26. short first, last;
  27.  
  28. void AVL_SHOW_UNIT(AVL_BIND_PTR w, short cols)
  29. {
  30.     short i,  k;    
  31.     short co;
  32.     char msg[35];
  33.     char fmt[20];
  34.     sprintf(fmt," %cc %c-%ds", '%', '%', cols);
  35.  
  36.     k = avl_cur_unit / 9;
  37.     first = k * 9;
  38.     last = first + 8;
  39.     if (last >= avl_size) 
  40.         last = avl_size - 1;
  41.     
  42.     _settextposition(1,1);
  43.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n");
  44.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n");
  45.     k = 1;
  46.     for(i = first; i <= last; ++i)  {
  47.         _settextposition(k,1);
  48.         if (i == avl_cur_unit)
  49.             co = _settextcolor(avl_men_ready);
  50.         else
  51.             co = _settextcolor(avl_men_letter);
  52.         sprintf(msg,fmt, k + '0', w[i].name);
  53.         _outtext(msg);
  54.         ++k;
  55.         }
  56.     _settextcolor(co);
  57. }
  58.                 
  59.  
  60. int AVL_UNIT(AVL_BIND_PTR w, int r)
  61. {
  62.         short x ;
  63.         short no = 0;
  64.         short ch, cols = 0, rows;
  65.         AVL_WIN_PTR hw, hw2;
  66.         if (r < 10)
  67.             rows = r;
  68.         else 
  69.             rows = 9;
  70.         avl_size = r;
  71.         avl_cur_unit = 0;
  72.  
  73.         /* Compute the maximum window's length */
  74.         for(x = 0; x < r; ++x)  
  75.             if ((no = strlen(w[x].name)) > cols)
  76.                 cols = no;
  77.  
  78.         cols += 4;
  79.         hw2 = AVL_MAKE_WINDOW("",15,55,15+9,55+24,avl_wnd_bk_color,avl_wnd_color);
  80.         _outtext(" Use the arrow keys to\n");
  81.         _outtext(" go  over  the  units.\n");
  82.         _outtext("\n");
  83.         _outtext(" Press  <enter>  to\n");
  84.         _outtext(" select  an  unit  or\n");
  85.         _outtext(" type  the  unit's no.\n");
  86.         _outtext("\n");
  87.         _outtext(" Press ESC to  cancel.");
  88.         hw = AVL_MAKE_WINDOW("",3,avl_menu[3].c,3+rows+1,avl_menu[3].c+cols+5,avl_wnd_bk_color,avl_wnd_color);
  89.  
  90.         while ( 1 )  {
  91.             AVL_SHOW_UNIT(w,cols-4);
  92.             ch = getch();
  93.             x = (last - first + 1);
  94.             if ((ch >= '1' && ch <= (x + '0')) || (ch == 13)) {
  95.                 if (ch != 13)
  96.                     avl_cur_unit += (ch - '0' - 1);
  97.                 AVL_DEL_WINDOW(hw);
  98.                 AVL_DEL_WINDOW(hw2);
  99.                 return avl_cur_unit;
  100.                 }
  101.             else {
  102.                 if (ch == 0 || ch == 0xE0) {
  103.                     ch = getch();
  104.                     switch( ch ) {
  105.                            case 73 : /* Page Up */ 
  106.                                avl_cur_unit -= rows;
  107.                                if (avl_cur_unit < 0)  
  108.                                 avl_cur_unit = avl_size - 1;
  109.                                break;
  110.                            case 81 : /* Page Down */ 
  111.                                avl_cur_unit += rows;
  112.                                if (avl_cur_unit >= avl_size)
  113.                                    avl_cur_unit = 0;
  114.                                break;
  115.                         case 72 : /* Up */ 
  116.                             if (--avl_cur_unit < 0)  
  117.                                 avl_cur_unit = avl_size - 1;
  118.                             break;
  119.                         case 80 : /* Down */ 
  120.                             if (++avl_cur_unit >= avl_size)
  121.                                 avl_cur_unit = 0;
  122.                             break;
  123.                         default : putchar(7); break;
  124.                         }
  125.                     continue;
  126.                     }
  127.                 if (ch == 27)  {
  128.                     AVL_DEL_WINDOW(hw);
  129.                     AVL_DEL_WINDOW(hw2);
  130.                     return -1;
  131.                     }
  132.                 putch(7);
  133.                 continue;
  134.                 }
  135.             }
  136. }            
  137.  
  138.  
  139.  
  140. void AVL_MAKE_BNAME(char *s, char *r)
  141. {
  142.     short i, j = 0;
  143.     char msg[50];
  144.     char *p;
  145.     p = r;
  146.     i = strlen(s) - 1;
  147.     while (*(s + i) != ' ') --i;
  148.     for(++i; *(s + i) != '\0'; ++i, ++r)
  149.         *r = *(s + i);
  150.     *r = '\0';
  151.     r = p;
  152.     if (strlen(p) > 10) {
  153.         i = strlen(p);
  154.         if (*(p + --i) == 'k' &&
  155.             *(p + --i) == 's' &&
  156.             *(p + --i) == 'a' &&
  157.             *(p + --i) == 't' &&
  158.             *(p + --i) == '_' &&
  159.             *(p + --i) == 'e' &&
  160.             *(p + --i) == 'l' &&
  161.             *(p + --i) == 'd' &&
  162.             *(p + --i) == 'i' &&
  163.             *(p + --i) == '_')  
  164.             *(p + i) = '\0';
  165.         }
  166. }    
  167.  
  168. void AVL_DELETE_ONE(short j, AVL_UNITDT_PTR w)
  169. {
  170.     short k;
  171.     w -> ns -= 1;
  172.     for(k = j; k < w -> ns; ++k) {
  173.         w -> s[k].status   = w -> s[k + 1].status; 
  174.         w -> s[k].is_main  = w -> s[k + 1].is_main;
  175.         strcpy(w -> s[k].fu,w -> s[k + 1].fu);
  176.         w -> s[k].cdate[0] = w -> s[k + 1].cdate[0];
  177.         w -> s[k].cdate[1] = w -> s[k + 1].cdate[1];
  178.         w -> s[k].cdate[2] = w -> s[k + 1].cdate[2];
  179.         w -> s[k].cdate[3] = w -> s[k + 1].cdate[3];
  180.         w -> s[k].cdate[4] = w -> s[k + 1].cdate[4];
  181.         }
  182. }    
  183.     
  184.  
  185. void AVL_DELETE_BNAME(short i,AVL_UNITDT_PTR w,char *s)
  186. {
  187.     short j, k;
  188.     char msg[50];
  189.     for(j = i + 1; j < w -> ns; ++j)  {
  190.         if (w -> s[j].is_main == ' ' && 
  191.             w -> s[j].fu[0] == 'b' &&
  192.             w -> s[j].fu[1] == 'i' &&
  193.             w -> s[j].fu[2] == 'n')  {
  194.             AVL_MAKE_BNAME(w -> s[j].fu,msg);
  195.             if (!strcmp(s,msg)) { 
  196.                 AVL_DELETE_ONE(j,w);
  197.                 break;
  198.                 }
  199.             }
  200.         }
  201. }
  202.                                 
  203. char *AVL_BIND_SELECT(AVL_UNITDT_PTR w)
  204. {
  205.     short rows, cols;
  206.     short i, j, k, n = 0, nc = 0;
  207.  
  208.     char msg[50];
  209.  
  210.     static AVL_BIND_SIZE r[AVL_MAX_UNITS];
  211.     AVL_BIND_SIZE c[AVL_MAX_UNITS];
  212.      
  213.     /* Pick obsolete units for compilation */
  214.     for(i = 0; i < w -> ns; ++i)  {
  215.         if (!strcmp(w -> s[i].fu,"subprogram DUMMY")) {
  216.             AVL_DELETE_ONE(i,w);
  217.             --i;
  218.             continue;
  219.             }
  220.         if (w -> s[i].status == 'O' && w -> s[i].is_main == 'M')   {
  221.                 if (nc >= AVL_MAX_UNITS) {
  222.                     AVL_ERROR("Too many units. Reinitialize library!");
  223.                     return;
  224.                     }
  225.                 c[nc].st = 'C';
  226.                 AVL_MAKE_BNAME(w -> s[i].fu,c[nc].name);
  227.                 /* An obsolete unit may be in "s" twice,
  228.                    therefore, it must be deleted */
  229.                 AVL_DELETE_ONE(i,w); /* Now there may be one left */
  230.                 AVL_DELETE_BNAME(-1,w,c[nc].name);
  231.                 ++nc;
  232.                 }
  233.         }
  234.  
  235.     for(i = 0; i < w -> ns; ++i)  
  236.         if (w -> s[i].status == 'A' && w -> s[i].is_main == 'M')   {
  237.             /*  Subprogram ready for binding */
  238.             if (n >= AVL_MAX_UNITS) {
  239.                 AVL_ERROR("Too many units. Reinitialize library!");
  240.                 return;
  241.                 }
  242.             r[n].st = 'B';
  243.             AVL_MAKE_BNAME(w -> s[i].fu,r[n].name);
  244.             AVL_DELETE_ONE(i,w);
  245.             --i;
  246.             ++n;
  247.             }
  248.  
  249.  
  250.     /*  Delete units that are already binded and ready for execution */
  251. /*  Allow all units to be binded 
  252.     for(i = 0; i < w -> ns; ++i)  
  253.         if (w -> s[i].status == 'A' && w -> s[i].is_main == ' ')   {
  254.             AVL_MAKE_BNAME(w -> s[i].fu, msg);
  255.             for(j = 0; j < n; ++j)  
  256.                 if (!strcmp(msg,r[j].name))  {
  257.                     --n;
  258.                     AVL_DELETE_ONE(i,w);
  259.                     for(k = j; k < n; ++k)  {
  260.                         r[k].st = r[k + 1].st;
  261.                         strcpy(r[k].name,r[k+1].name);
  262.                         }
  263.                     --i;
  264.                     break;
  265.                     }
  266.             }                
  267. */
  268.  
  269.     if (n > 0)
  270.         i = AVL_UNIT(r,n);
  271.     else {
  272.         i = -1;
  273.         AVL_ERROR("First compile any executable program unit.");
  274.         }
  275.     if (i >= 0)
  276.         return r[i].name;
  277.     return NULL;
  278. }
  279.         
  280.  
  281. void AVL_BIND()
  282. {
  283.     AVL_EDIT_WINDOW_PTR ww;
  284.     AVL_WIN_PTR temp;
  285.     char msg[100];
  286.     char *bunit;
  287.     char *opts[17];
  288.     AVL_UNITDT w;
  289.     short cmd_ret_code, i;
  290.     FILE *fp, *fopen();
  291.     avl_blank_line[0] = '\0';
  292. /*    w = &avl_windows[avl_window];  */
  293.     w.ns = 0;
  294.     opts[0] = "Adalib2";
  295.     opts[1] = "-l";
  296.     opts[2] = avl_dir_library;
  297.     opts[3] = NULL;
  298.     unlink("gwada.smm");
  299.     temp = AVL_MAKE_WINDOW(" Binding ",5,1,9,80,avl_wnd_bk_color,avl_wnd_color);
  300.     _outtext("  Searching library. Please, wait a moment...\n");
  301.     if (AVL_EX_UNIT("ADALIB2", opts))  {
  302.         AVL_DEL_WINDOW(temp);
  303.         msg[0] = '\0';
  304.         AVL_MAKE_UNIT_DATE(&w);
  305.         if (w.ns > 0)  {
  306.             bunit = AVL_BIND_SELECT(&w);
  307.             if (bunit != NULL)  {
  308.                 sprintf(msg," %s\n", bunit);
  309.                 temp = AVL_MAKE_WINDOW(" Binding ",5,1,8,80,avl_wnd_bk_color,avl_wnd_color);
  310.                 _outtext(msg);
  311.                 opts[0] = "Adabind"